//
//  UIBarButtonItem+buttonItem.m
//  ALbaisibudejie
//
//  Created by 安林 on 16/8/30.
//  Copyright © 2016年 安林. All rights reserved.
//

#import "UIBarButtonItem+buttonItem.h"

@implementation UIBarButtonItem (buttonItem)


+ (UIBarButtonItem *)barButtonItemWith:(UIButton *)button addTarget:(id)target action:(SEL)selector andImage:(NSString *)imageName andHighlighted:(NSString *)highlightImage{
    
    
    
    // 设置右边(穿越❌)
    
    // 把上面的奖杯等包装成view
    //UIView *view = [[UIView alloc]init];
    //[view addSubview:button];

    
    // 右边按钮的单击
    [button addTarget:target action:selector forControlEvents:UIControlEventTouchUpInside];
    
    // 设置未点击时的照片
    [button setImage:[UIImage imageNamed:imageName] forState:UIControlStateNormal];
    // 设置单击时的照片
    [button setImage:[UIImage imageNamed:highlightImage] forState:UIControlStateHighlighted];
    [button sizeToFit]; // 自动适应大小
    
    
    // 当把UIButton包装成UIBarButton时，单击的范围会自动扩大
    UIBarButtonItem *item = [[UIBarButtonItem alloc]initWithCustomView:button];
    
    return item;
}



+ (UIBarButtonItem *)barButtonItemWith:(UIButton *)button addTarget:(id)target action:(SEL)selector andImage:(NSString *)imageName andSelectImage:(NSString *)selectImage{
    
    
    
    // 设置右边(穿越❌)
    
    // 把上面的奖杯等包装成view
    //UIView *view = [[UIView alloc]init];
    //[view addSubview:button];

    // 右边按钮的单击
    [button addTarget:target action:selector forControlEvents:UIControlEventTouchUpInside];
    
    // 设置未点击时的照片
    [button setImage:[UIImage imageNamed:imageName] forState:UIControlStateNormal];
    // 设置单击时的照片
    [button setImage:[UIImage imageNamed:selectImage] forState:UIControlStateSelected];
    [button sizeToFit]; // 自动适应大小
    
    
    // 当把UIButton包装成UIBarButton时，单击的范围会自动扩大
    UIBarButtonItem *item = [[UIBarButtonItem alloc]initWithCustomView:button];
    
    
    
    return item;
}

@end
